package com.springcloud.feigndemo.pojo

import org.springframework.http.MediaType
import org.springframework.util.FileCopyUtils
import org.springframework.web.multipart.MultipartFile

class MyMultipartFile implements MultipartFile{

    String  name,
            contentType
    File file

    MyMultipartFile(String name,MediaType contentType,File original){
        this.name=name
        this.contentType=contentType.getType()
        file=original
    }
    @Override
    String getName() {

        return name
    }

    @Override
    String getOriginalFilename() {
        return file.getName()
    }

    @Override
    String getContentType() {
        return contentType
    }

    @Override
    boolean isEmpty() {
        return !(file.size()>0)
    }

    @Override
    long getSize() {
        return file.size()
    }

    @Override
    byte[] getBytes() throws IOException {
        return file.getBytes()
    }

    @Override
    InputStream getInputStream() throws IOException {
        return new FileInputStream(file)
    }

    @Override
    void transferTo(File dest) throws IOException, IllegalStateException {
        FileCopyUtils.copy(file, dest);
    }
}
